import numpy as np
import pandas as pd
# print(help(pd))

# 系列
# s=pd.Series([1,3,np.nan,7,9])
s=pd.Series(2,index=list(range(4)),dtype='float32')
print(16*"--","系列")
print(s)

# 数据帧
dates=pd.date_range(start='20170101',periods=5)
print(16*"--","数据帧1")
df=pd.DataFrame(data=np.random.randn(5,4),index=dates,columns=list('ABCD'))
print(df)
# print("调换数据")
# print(df.T)
# print("头",df.head(1))
# print("尾",df.tail(2))
# print("A列\n",df['A'])#相当于df.A
# print("3-5",df[2:5]) #从0开始，[2,5)
# print("20170101-20170103",df['20170101':'20170103'])
# print('标签选择',df.loc[dates[0]])


print(16*"--","数据帧2")
df1=pd.DataFrame({
    "A":range(3,7),
    "B":pd.Series(2,index=list(range(4)),dtype='float32'),
    "C":np.array([3]*4,dtype='int32'),
    "D":pd.Categorical(["test","train","test","train"]),
})
print(df1)
# print("统计摘要")
# print(df1.describe())
# print("index:",df1.index)
# print("columns:",df1.columns)
# print("values:",df1.values)
# print("轴排序：")
# print(df.sort_index(axis=1,ascending=False))
# print("值排序：")
# print(df.sort_values(by='B'))
# print("布尔索引\n",df1[df1.D.isin(['test'])])
print("布尔索引\n",df1[df1.A>3])